<template>
	<view v-show="!isSortType" :style="{padding:'0 '+prConfig+'px'}">
		<!-- cateList -->
		<view class="cateList">
			<view class="item" v-for="(item,index) in cateList" :key="index" :class="index===tabClick?'click':''" @click="longClick(item,index)">
				<view class="title">
					{{item.cate_name}}
				</view>
				<!-- <view class="msg">
					{{item.cate_mark}}
				</view> -->
			</view>
		</view>

		
		<view class="index-product-wrapper" :class="bgStyle===0?'':'borderRadius15'" :style="{ marginTop: mbConfig*2 + 'rpx', background: themeColor }" v-if="tempArr.length">
			<!-- 单列 -->
			<block v-if="itemStyle == 0">
				<view class="list-box listA" :class="tempArr.length > 0 ? 'fadeIn on' : ''">
					<view class="item" :class="conStyle?'borderRadius15':''" v-for="(item, index) in tempArr" :key="index" @click="goDetail(item)">
						<view class="pictrue">
							<span class="pictrue_log pictrue_log_class" :style="'background-color:'+labelColor" v-if="item.activity && item.activity.type === '1'">抢单</span>
							<span class="pictrue_log pictrue_log_class" :style="'background-color:'+labelColor" v-if="item.activity && item.activity.type === '2'">砍价</span>
							<span class="pictrue_log pictrue_log_class" :style="'background-color:'+labelColor" v-if="item.activity && item.activity.type === '3'">拼团</span>
							<image :src="item.image" mode="aspectFill"></image>
						</view>
						<view class="text-info" style="display: flex; flex-direction: column; justify-content: space-between;">
							<view>
								<view class="title line2" v-if="titleShow">{{ item.store_name }}</view>
								<view class="old-price" v-if="opriceShow">
									<text>¥</text>
									{{ item.ot_price }}
								</view>
							</view>
							<view class="price" :style="'color:'+fontColor">
								<view v-if="priceShow">
									<text>￥</text>
									{{ item.price }}
								</view>
								<view class="txt" :style="'border:1px solid '+labelColor+';color:'+labelColor" :class="priceShow?'':'on'" v-if="item.checkCoupon && couponShow">券</view>
							</view>
						</view>
					</view>
				</view>
			</block>
			<!-- 两列 -->
			<block v-if="itemStyle == 1">
				<view class="list-box listC" :class="tempArr.length > 0 ? 'fadeIn on' : ''">
					<view class="item" :class="conStyle?'borderRadius15':''" v-for="(item, index) in tempArr" :key="index" @click="goDetail(item)">
						<view class="pictrue">
							<span class="pictrue_log pictrue_log_class" :style="'background-color:'+labelColor" v-if="item.activity && item.activity.type === '1'">抢单</span>
							<span class="pictrue_log pictrue_log_class" :style="'background-color:'+labelColor" v-if="item.activity && item.activity.type === '2'">砍价</span>
							<span class="pictrue_log pictrue_log_class" :style="'background-color:'+labelColor" v-if="item.activity && item.activity.type === '3'">拼团</span>
							<image :src="item.image" mode="aspectFill"></image>
						</view>
						<view class="text-info">
							<view class="title line1" v-if="titleShow">{{ item.store_name }}</view>
							<view class="old-price" v-if="opriceShow">
								<text>¥</text>
								{{ item.ot_price }}
							</view>
							<view class="price" :style="'color:'+fontColor">
								<view v-if="priceShow">
									<text>￥</text>
									{{ item.price }}
								</view>
								<view class="txt" :style="'border:1px solid '+labelColor+';color:'+labelColor" :class="priceShow?'':'on'" v-if="item.checkCoupon && couponShow">券</view>
							</view>
						</view>
					</view>
				</view>
			</block>
			<!-- 三列 -->
			<block v-if="itemStyle == 2">
				<view class="list-box listB" :class="tempArr.length > 0 ? 'fadeIn on' : ''">
					<view class="item" :class="conStyle?'borderRadius15':''" v-for="(item, index) in tempArr" :key="index" @click="goDetail(item)">
						<view class="pictrue">
							<span class="pictrue_log pictrue_log_class" :style="'background-color:'+labelColor" v-if="item.activity && item.activity.type === '1'">抢单</span>
							<span class="pictrue_log pictrue_log_class" :style="'background-color:'+labelColor" v-if="item.activity && item.activity.type === '2'">砍价</span>
							<span class="pictrue_log pictrue_log_class" :style="'background-color:'+labelColor" v-if="item.activity && item.activity.type === '3'">拼团</span>
							<image :src="item.image" mode="aspectFill"></image>
						</view>
						<view class="text-info" style="display: flex; flex-direction: column; justify-content: space-between;">
							<view>
								<view class="title line1" v-if="titleShow">{{ item.store_name }}</view>
								<view class="old-price" v-if="opriceShow">
									<text>¥</text>
									{{ item.ot_price }}
								</view>
							</view>
							<view class="price" :style="'color:'+fontColor">
								<view v-if="priceShow">
									<text>￥</text>
									{{ item.price }}
								</view>
								<view class="txt" :style="'border:1px solid '+labelColor+';color:'+labelColor" :class="priceShow?'':'on'" v-if="item.checkCoupon && couponShow">券</view>
							</view>
							
						</view>
					</view>
				</view>
			</block>
		</view>
		<!-- 大图 -->
		<block v-if="itemStyle == 3 && tempArr.length" :style="{ marginTop: mbConfig + 'rpx' }">
			<view class="listBig" :class="bgStyle===0?'':'borderRadius15'" :style="{ background: themeColor }">
				<view class="itemBig" :class="conStyle?'borderRadius15':''" v-for="(item,index) in tempArr" :key="index" @click="goDetail(item,1)">
					
					<view class="img-box">
						<span class="pictrue_log_big pictrue_log_class" :style="'background-color:'+labelColor" v-if="item.activity && item.activity.type === '1'">抢单</span>
						<span class="pictrue_log_big pictrue_log_class" :style="'background-color:'+labelColor" v-if="item.activity && item.activity.type === '2'">砍价</span>
						<span class="pictrue_log_big pictrue_log_class" :style="'background-color:'+labelColor" v-if="item.activity && item.activity.type === '3'">拼团</span>
						<image :src="item.recommend_image" mode="aspectFill" v-if="item.recommend_image"></image>
						<image :src="item.image" mode="aspectFill" v-else></image>
					</view>
					<view class="name line2 fengexian"><span class="coupon" :style="'border:1px solid '+labelColor+';color:'+labelColor" v-if="item.checkCoupon && couponShow">券</span><span v-if="titleShow">{{item.store_name}}</span></view>
					 <view class="introduce_bottom" :style="'color:'+fontColor" v-if="item.touzi_shouyi_bill_arr.length && item.touzi_month_arr.length && item.touzi_shouyi_arr.length">
						 
						 <view v-if="item.touzi_month_arr">
						 	<view class="title">
						 		{{item.touzi_month_arr[1]}}
								
						 	</view>
						 	<view class="msg">
						 		{{item.touzi_month_arr[0]}}
						 	</view>
						 </view>
						 <view v-if="item.touzi_shouyi_bill_arr">
						 	<view class="title">
						 		{{item.touzi_shouyi_bill_arr[1]}}
						 	</view>
						 	<view class="msg">
						 		{{item.touzi_shouyi_bill_arr[0]}}
						 	</view>
						 </view>
						 <view v-if="item.touzi_shouyi_arr">
						 	<view class="title">
						 		{{item.touzi_shouyi_arr[1]}}
						 	</view>
						 	<view class="msg">
						 		{{item.touzi_shouyi_arr[0]}}
						 	</view>
						 </view>
						 <view v-if="item.price">
						 	<view class="title" :style="'color:'+fontColor">
						 		{{item.price}}
						 	</view>
						 	<view class="msg">
						 		采购价格
						 	</view>
						 </view>

					  </view>
					  <view class="price fengexian" :style="'color:'+fontColor" v-else><span v-if="priceShow">￥<span class="num">{{item.price}}</span></span><span class="old-price"
					  	 v-if="opriceShow">¥{{item.ot_price}}</span>
					   </view>
					   
					<view class="" style="padding-bottom: 30rpx;border-top: 2px solid #f0f0f0;" v-if="item.merch_name">
						
						<view class="caigouheader">
							<view class="caigoujindu titleStyle">
								<!-- 采购进度 -->
								{{item.merch_name}}
							</view>
							<view class="caigoujindu gobutton">
								立即采购
							</view>
						</view>
						<!-- <view class="progress">
							<view class='bg-reds' :style="'width:'+item.percent+'%;'"></view>
							<view class='piece'>已抢{{item.percent}}%</view>
						</view> -->
					</view>
				</view>
			</view>
		</block>
		
		<uni-load-more :status="page.status" @clickLoadMore="loadMore" :content-text="contentText"></uni-load-more>
		
	</view>
</template>

<script>
	import {
		getProductslist,
	} from '@/api/store.js';
	import { GetIndexCateList } from '@/api/api.js';
	export default {
		name: 'goodList',
		props: {
			dataConfig: {
				type: Object,
				default: () => {}
			},
			isSortType: {
				type: String | Number,
				default: 0
			}
		},
		data() {
			return {
				tempArr: [],
				mbConfig: this.dataConfig.mbConfig.val,
				numConfig: this.dataConfig.numConfig.val,
				themeColor: this.dataConfig.themeColor.color[0].item,
				itemStyle: this.dataConfig.itemStyle.type,
				sortType: this.dataConfig.goodsSort.type,
				type: this.dataConfig.tabConfig.tabVal || 0,
				selectId: this.dataConfig.selectConfig.activeValue,
				productIds: this.dataConfig.goodsList.ids || [],
				opriceShow: this.dataConfig.opriceShow.val, //商品原价
				priceShow: this.dataConfig.priceShow.val, //商品价格
				titleShow: this.dataConfig.titleShow.val, //商品名称
				couponShow: this.dataConfig.couponShow.val, //商品提货卡
				prConfig: this.dataConfig.prConfig.val, //左右边距
				bgStyle: this.dataConfig.bgStyle.type,//背景样式
				conStyle: this.dataConfig.conStyle.type,//内容样式
				fontColor: this.dataConfig.fontColor.color[0].item,
				labelColor: this.dataConfig.labelColor.color[0].item,
				cateList:[],
				tabClick:0,
				defaultId:0,
				page: {
					length:0,
					status: 'more',
					total: 0, //总页数
					pageSize: 10, //每页条数
					pageNum: 1 //默认当前页
				},
				contentText: {
					contentdown: '查看更多',
					contentrefresh: '加载中',
					contentnomore: '没有更多数据了'
				}
		
			};
		},
		created() {
			console.log(this.dataConfig)
		},
		mounted() {
			
			this.GetIndexCateList();
			
		},
		methods: {
			GetIndexCateList(){
				
				GetIndexCateList().then(res => {
					this.cateList = res.data;
					this.defaultId = res.data[0].id;

					this.productslist();
				});
				// 
			},
			// 点击
			longClick(item, index) {
				
				this.tabClick = index //设置导航点击了哪一个
				this.defaultId = item.id;
				this.page.pageNum = 1;
				this.tempArr=[]
				this.productslist();
				
			},
			productslist() {
				let limit = this.$config.LIMIT;
				let data = {};
				if(this.defaultId>0){
					data = {
						sid:this.defaultId,
						priceOrder: this.sortType == 2 ? 'desc' : '',
						salesOrder: this.sortType == 1 ? 'desc' : '',
						selectId: this.selectId[this.selectId.length-1] || 0,
						limit: this.numConfig
					};
				}else if (this.type == 1) {
					data = {
						ids: this.productIds.join(','),
					};
				} else {
					data = {
						priceOrder: this.sortType == 2 ? 'desc' : '',
						salesOrder: this.sortType == 1 ? 'desc' : '',
						selectId: this.selectId[this.selectId.length-1] || 0,
						limit: this.numConfig
					};
				}
				data.page=this.page.pageNum
				data.limit=this.page.pageSize
				this.page.status='loading'
				getProductslist(data).then(res => {
					this.tempArr = this.tempArr.concat(res.data)
					this.page.length = res.data.length
					if(this.page.length == this.page.pageSize){
						this.page.status='more'
					}else{
						this.page.status='no-more'
					}
				});
			},
			loadMore(){
				if(this.page.length == this.page.pageSize){
					this.page.pageNum++
					
					// 加载数据
					this.productslist()
				}
			}
			,
			goDetail(item) {
				this.$emit('detail', item,1);
			},
		}
	};
</script>

<style lang="scss">
	.cateList{
		width: 100%;
		height: 80rpx;
		line-height: 80rpx;
		margin-top: 29rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;
		
		/*段落中文本不换行*/
		white-space: nowrap;
		/*设置横向滚动*/
		overflow-x: scroll;
		/*禁止纵向滚动*/
		overflow-y: hidden;
		/*文本平铺*/
		text-align: justify;
		.cateList::-webkit-scrollbar {
			/*隐藏滚动条*/
			display: none;
		}
		
		.item {
			padding: 0 20rpx;
			text-align: center;
			width: 25%;
			height: 100%;
			
			&:not(:last-child) {
				// border-right: 1px solid #ededed;
			}
			
			.title {
				
				font-size: 34rpx !important;
				color: #333333;
				font-weight: bold;	
			
			}
			
			
			.msg {
				// margin-top: 15rpx;
				padding: 0 20rpx;
				font-size: 26rpx !important;
				color: #999;
				width: 100% !important;
			}
		}
		.click {
			text-align: center;
			width: 25%;
			height: 100%;
			
			.title {
				border-bottom: 5rpx solid #f9552a;
				line-height: 60rpx;
				font-size: 34rpx;
				color: rgb(249, 84, 41);
			}
			
			.msg {
				font-size: 25rpx;
				background: rgb(249, 84, 41);
				color: rgb(255, 255, 255);
				display: flex;
				align-items: center;
				justify-content: center;
				border-radius: 20rpx;
				margin: auto;
				width: 70%;
			}
		}
		
		// .item{
		// 	width: 25%;
		// 	height: 50rpx;
		// 	display: inline-block;
		// 	line-height: 50rpx;
		// 	text-align: center;
		// 	font-size: 30rpx;
		// 	overflow: hidden;
		// 	text-overflow: ellipsis;
		// 	white-space: nowrap;
		// 	&.click {
		// 		font-weight: bold;
		// 	}
		// }
	}
	.caigouheader{
		width: 100%;
		display: flex;
		justify-content: space-between;
		align-items: center;
		height: 60rpx;
		line-height: 60rpx;
		padding-left: 20rpx;
		margin-top: 20rpx;
		.caigoujindu{
			text-align: center;
			// width: 33%;
			height: 100%;
		}
		.gobutton{
			width: 25%;
			background: #02b7ec;
			color: white;
			margin-right: 20px;
			border-radius: 20rpx;
			// padding-right: 30rpx;
		}
	}
	
	.introduce_bottom {
		width: 100%;
		margin-top: 29rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;
		border-top: 1px solid #e2e7ea;
		
		>view {
			padding: 20rpx 0;
			text-align: center;
			width: 33%;
			height: 100%;
	
			&:not(:last-child) {
				// border-right: 1px solid #ededed;
			}
	
			.title {
				font-size: 30rpx;
				color: #333333;
				font-weight: bold;
			}
	
			.msg {
				// margin-top: 15rpx;
				font-size: 24rpx;
				color: #999999;
			}
		}
	}
	.fengexian{
		width: 100%;
		height: 80rpx;
		line-height: 80rpx;
		border-top: 2px solid #f0f0f0;
	}
	.progress {
		overflow: hidden;
		background-color: #aaa7a7;
		width: 100%;
		border-radius: 18rpx;
		height: 40rpx;
		position: relative;
		margin-top: 20rpx;
	}
	
	.progress .bg-reds {
		width: 0;
		height: 100%;
		transition: width 0.6s ease;
		background: linear-gradient(90deg, rgba(233, 51, 35, 1) 0%, rgba(255, 137, 51, 1) 100%);
	}

	.progress .piece {
		position: absolute;
		left: 8%;
		transform: translate(0%, -50%);
		top: 49%;
		font-size: 16rpx;
		color: #ffffff;
	}
	.listBig {
		// padding: 0px 10rpx 10rpx 10rpx;
		.borderRadius15{
			image{
				border-radius: 20rpx 20rpx 0 0;
			}
		}

		.itemBig {
			width: 100%;
			margin-top: 20rpx;
			background-color: #fff;
			padding-bottom: 15rpx;
			
			.img-box {
				width: 100%;
				height: 370rpx;
				position: relative;
				padding-top: 15rpx;
				.pictrue_log_big{
					border-radius: 20rpx 0 20rpx 0;
				}
				image {
					width: 100%;
					height: 100%;
				}
			}

			.name {
				font-size: 28rpx;
				font-weight: bold;
				margin-top: 16rpx;
				padding: 0 8px;
				// height: 80rpx;
				// line-height: 80rpx;
				.coupon {
					display: inline-block;
					text-align: center;
					width: 32rpx;
					border-radius: 4rpx;
					font-size: 20rpx;
					font-weight: normal;
					margin-right: 10rpx;
				}
			}

			.price {
				font-weight: bold;
				font-size: 12px;
				margin-top: 10rpx;
				padding: 0 8px;

				.num {
					font-size: 32rpx;
					margin-right: 10rpx;
				}

				.old-price {
					color: #aaa;
					font-weight: normal;
					text-decoration: line-through;
				}
			}
		}
	}

	.index-product-wrapper {

		.list-box {
			display: flex;
			flex-wrap: wrap;
			justify-content: space-between;
			padding: 20rpx 20rpx 0;

			.item {
				width: 345rpx;
				margin-bottom: 20rpx;
				background-color: #fff;
				overflow: hidden;
				position: relative;

				&.on {
					border-radius: 0;
				}

				.pictrue {
					width: 347rpx;
					height: 347rpx;
				}

				.pictrue_log {
					width: 92rpx;
					height: 44rpx;
					font-size: 26rpx;
					line-height: 44rpx;
					border-radius: 0 0 20rpx 0!important;
				}

				image {
					width: 100%;
					// height: 346rpx;
					height: 100%;
					display: block;
				}

				.text-info {
					padding: 10rpx 20rpx 15rpx;

					.title {
						color: #222222;
					}

					.old-price {
						margin-top: 4rpx;
						font-size: 26rpx;
						color: #aaaaaa;
						text-decoration: line-through;

						text {
							margin-right: 2px;
							font-size: 20rpx;
						}
					}

					.price {
						display: flex;
						align-items: flex-end;
						font-size: 36rpx;
						font-weight: 550;

						text {
							padding-bottom: 4rpx;
							font-size: 26rpx;
							font-weight: normal;
						}

						.txt {
							display: flex;
							align-items: center;
							justify-content: center;
							width: 28rpx;
							height: 28rpx;
							margin-left: 15rpx;
							margin-bottom: 10rpx;
							border-radius: 4rpx;
							font-size: 20rpx;
							font-weight: normal;

							&.on {
								margin-left: 0;
							}
						}
					}
				}
			}

			&.on {
				display: flex;
			}

			&.listA {
				.item {
					display: flex;
					width: 100%;

					.pictrue {
						width: 220rpx;
						height: 220rpx;
					}

					.text-info {
						// width: 490rpx;
						flex: 1
					}
				}
			}

			&.listC {
				.item{
					width: 48.5%;
				}
				.pictrue {
					width: 100%;
					height: 345rpx;
				}
			}

			&.listB {
				justify-content: inherit;

				.item {
					width: 31.6%;
					margin-right: 16rpx;

					.pictrue {
						width: 100%;
						height: 220rpx;
					}

					&:nth-child(3n) {
						margin-right: 0;
					}
				}
			}
		}
	}
	.titleStyle{
		color: #02b7ec;
		font-size: 16px;
		font-weight: 900;
	}
	
</style>
